home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-19 | 7.8 KB | 322 lines | [TEXT/MPS ] |
- (*********** Auxiliary routines ********************************************************)
-
- PROCEDURE DoUpdate(theEvent : EventRecord);
- FORWARD;
-
- PROCEDURE ErrorControl(message: Str255);
-
- BEGIN
- DebugStr(message);
- END;
-
- (* The sample wants to show how callbacks are triggered over a period of time with
- each invokation comming every three seconds, thererfor we need
- the movie to have a reasonable duration. In this routine we extend the duration of
- the movie if the duration is less than kMinDuration seconds.
- *)
-
- PROCEDURE ExtendMovie(whichMovie: Movie);
- VAR moovDuration, desiredDuration: TimeValue;
- times, count: Integer;
- temp: Movie;
- moovScale: TimeScale;
-
- BEGIN
- moovDuration := GetMovieDuration(whichMovie);
-
- (* need to convert our desired duration in seconds to movie time
- so that we can compare what we want with the original duration *)
- moovScale := GetMovieTimeScale(whichMovie);
- desiredDuration := moovScale * kMinDuration; (* convert to movie time *)
-
- IF moovDuration < desiredDuration THEN (* compare durations *)
- BEGIN
- times := desiredDuration DIV moovDuration;
- SetMovieSelection(whichMovie, 0, moovDuration); (* select whole movie *)
- temp := CopyMovieSelection(whichMovie); (* and cut it *)
- SetMovieSelection(whichMovie, moovDuration, moovDuration); (* select the end *)
- FOR count := 1 to times DO
- BEGIN
- PasteMovieSelection(whichMovie, temp); (* add movie to itself *)
- moovDuration := GetMovieDuration(whichMovie); (* get the new duration *)
- SetMovieSelection(whichMovie, moovDuration, moovDuration); (* select the end *)
- END;
- DisposeMovie(temp);
- END
- END;
-
-
- (* Sets the movie clip region in order to display only a piece of it *)
- PROCEDURE SplitMovie(moov: Movie; count: Integer);
- VAR cBox: Rect;
- rectRgn: RgnHandle;
-
- BEGIN
- rectRgn := NewRgn;
- GetMovieBox(moov, cBox);
-
- WITH cBox DO
- CASE count OF
- 1:BEGIN
- right := right DIV 2;
- bottom := bottom DIV 2;
- END;
- 2:BEGIN
- left := right DIV 2;
- bottom := bottom DIV 2;
- END;
- 3:BEGIN
- left := right DIV 2;
- top := bottom DIV 2;
- END;
- 4:BEGIN
- right := right DIV 2;
- top := bottom DIV 2;
- END
- END; (* CASE *)
-
- OpenRgn;
- FrameRect(cBox);
- CloseRgn(rectRgn);
-
- SetMovieClipRgn(moov, rectRgn);
-
- DisposeRgn(rectRgn);
- END;
-
-
- PROCEDURE HandleGoAway(WPtr : WindowPtr; MLoc : Point);
- {
- purpose handle mouse click in go-away box
- }
- VAR
- WPeek : WindowPeek; { for looking at windows }
- BEGIN
- IF WPtr = FrontWindow THEN { if it's the active window }
- BEGIN
- WPeek := WindowPeek(WPtr); { peek at the window }
- IF TrackGoAway(WPtr,MLoc) THEN { and the box is clicked }
- IF WPeek^.WindowKind = userKind THEN{ if it's our window }
- gDoneFlag := True { then time to stop }
- END
- ELSE
- SelectWindow(WPtr) { else make it active }
- END; { of proc HandleGoAway }
-
- PROCEDURE ShiftMoviePieces(count: Integer);
- VAR cBox: Rect;
- pos: Integer;
- hOff, vOff: Integer;
-
- BEGIN
-
- GetMovieBox(gMoov[count], cBox);
-
- WITH cBox DO
- BEGIN
- hOff := (right - left);
- vOff := (bottom - top);
- END;
-
- pos := count + stage;
- IF pos > 4 THEN
- pos := pos - 4;
- CASE pos OF
- 1:BEGIN
- hOff := 0;
- vOff := -vOff;
- END;
- 2:BEGIN
- vOff := 0;
- END;
- 3:BEGIN
- hOff := 0;
- END;
- 4:BEGIN
- vOff := 0;
- hOff := -hOff;
- END
- END; (* CASE *)
-
- OffSetRect(cBox, hOff, vOff);
- SetMovieBox(gMoov[count], cBox);
- END;
-
- PROCEDURE HandleClicks;
- VAR j: Integer;
-
- BEGIN
- stage := (stage +1) MOD 4;
-
- FOR j:= 1 TO MoviePieces DO
- BEGIN
- ShiftMoviePieces(j);
- END;
-
- END;
-
- PROCEDURE DoMouseDown(theEvent:EventRecord);
- {
- purpose identify where mouse was clicked and handle it
- }
- VAR
- Location : Integer;
- theWindow : WindowPtr;
- MLoc : Point;
- WLoc : Integer;
-
- PROCEDURE DoButtonDown;
- {
- }
- VAR
- t1, t2: Integer;
- result: ComponentResult;
- setInvisible: Boolean;
- err: OSErr;
- controllerBox: Rect;
- BEGIN
- t1 := TickCount;
- REPEAT
- t2 := TickCount;
- UNTIL NOT WaitMouseUp;
-
- IF t2 - t1 > 5 THEN
- BEGIN
- HandleClicks
- END
- END;{ of proc DoButtonDown }
-
- BEGIN
- MLoc := theEvent.Where; { get mouse position }
- WLoc := FindWindow(MLoc,theWindow); { get window, loc in window }
- CASE WLoc OF { handle window locations }
- InGoAway : HandleGoAway(theWindow,MLoc); { in the go away box}
- OTHERWISE DoButtonDown;
- END;
- END; { of proc DoMouseDown }
-
- PROCEDURE HandleEvent(theEvent : EventRecord);
- {
- purpose decodes events and dispatched to handlers
- }
- BEGIN
- CASE theEvent.What OF
- mouseDown: DoMouseDown(theEvent); { mouse button pushed }
- updateEvt: DoUpdate(theEvent);
- END
- END; { of proc HandleEvent }
-
- PROCEDURE InitVars;
- BEGIN
- { Initialization of variables used for time base samples }
- doneSizing := FALSE; { We want to resize the window just once }
- stage := 0; { Where in the rotation we are }
- enslaving := TRUE; { Using the time base slaving trick }
- gDoneFlag := FALSE; { to begin with }
- gForwardFlag := TRUE; { start the movie playing forward }
- END;
-
- FUNCTION InitSystem: OSErr;
- {
- purpose initialize everything for the program
- returns an error if QuickTIme is not present or
- if EnterMovies failed.
- }
- VAR
- result: OSErr;
-
- FUNCTION GetGestaltResult(gestaltSelector: OSType):Integer;
- VAR
- result : LONGINT;
- BEGIN
- IF Gestalt(gestaltSelector, result) = noErr THEN
- GetGestaltResult := result
- ELSE
- GetGestaltResult := 0;
- END;
-
- BEGIN
-
- MaxApplZone;
-
- { initialize all the different managers }
- InitGraf(@thePort); { create a grafport for the screen }
- InitFonts; { start up the font manager }
- InitWindows; { start up the window manager }
- InitMenus; { start up the menu manager }
- TEInit; { start up the text manager for DAs }
- InitDialogs(NIL); { start up the dialog manager }
- FlushEvents(everyEvent,0); { clear events from previous state }
-
- WITH wRect DO { Use this routine to init the window rect }
- BEGIN
- top:= 40;
- left:= 20;
- bottom := 240;
- right := 220;
- END;
-
- gSystemVersion := GetGestaltResult (gestaltSystemVersion);
-
- IF GetGestaltResult(gestaltQuickTime) <> 0 THEN { zero means no such selector }
- result:= EnterMovies
- ELSE
- result := movieToolboxUnitialized;
-
- { Initialization of variables used for time base samples }
- InitVars;
-
- InitSystem := result;
- END; (* InitSystem *)
-
- PROCEDURE ConvertOldToNew(oldSF: SFReply; VAR newSF: StandardFileReply);
- {
- purpose converts an old style SFReply inot a system 7
- StandardFileReply.
- }
- VAR err: OSErr;
- ignoreProc: LONGINT;
-
- BEGIN
- WITH newSF, oldSF DO
- BEGIN
- sfGood := good;
- sfReplacing := copy;
- sfType := fType;
- err := FSMakeFSSpec(vRefNum, 0, fName, sfFile);
- sfScript := iuSystemScript;
- sfFlags := 0;
- sfIsFolder := false;
- sfIsVolume := false;
- sfReserved1 := 0;
- sfReserved2 := 0;
- END;
- END;
-
- FUNCTION DisplayGetFile(prompt: Str255; VAR reply: StandardFileReply): BOOLEAN;
- {
- purpose promp the user to select a file works in both system 6 and 7.
- }
- VAR fileTypes: SFTypeList;
- localReply: SFReply;
- where: Point;
- err: OSerr;
- BEGIN
- where.h:=100;
- where.v:=100;
- fileTypes[0]:='MooV';
-
- IF gSystemVersion >= $0700 THEN { new standard file available }
- StandardGetFilePreview(nil, 1, fileTypes, reply)
- ELSE
- BEGIN
- SFGetFIle(where, prompt, nil, 1, fileTypes, nil, localReply);
- ConvertOldToNew(localReply, reply);
- END;
- DisplayGetFile := reply.sfGood;
- END;
-
-
- (******* END Auxiliary routines ********************************************************)
-
-